function printPage() {
	
	titulo = document.title;
	label = page_title.innerHTML;
	conteudo = content.innerHTML;
	
	top.ref = openWindow('print.do');
	i = 0;
	while (top.ref.document.readyState != "complete") {
		i++;
	}
	if (!top.ref.closed && top.ref.document.readyState == "complete") {
		top.ref.content.innerHTML = conteudo;
		top.ref.page_title.innerHTML = label;
		top.ref.document.title = titulo;
		top.ref.print();
	}
}

function openWindow(url) {
	win_width = 0;
	win_height = 0;
	if (screen.availWidth >= 1024) {
		win_width = 800;
		win_height = 600;
	} else {
		win_width = 640;
		win_height = 480;
	}

	return openWindowWH(url, win_width, win_height);
}

function openWindowWH(url, win_width, win_height, options) {
	if ( options == null) {
		options = 'menubar=0, toolbar=0, status=0, scrollbars=1, resizable=1';
	}

	win_top = Math.round((screen.availHeight - win_height) / 2);
	win_left = Math.round((screen.availWidth - win_width) / 2);

	return window.open(url,null,
		'left=' + win_left + ', top=' + win_top + ', width=' + win_width + ', height=' + win_height + 
		', ' + options);
}

function setContent(ref, content, title) {
	if (!ref.closed) {
		if (ref.document.readyState == "complete") {
			ref.content.innerHTML = content;
			ref.page_title.innerHTML = title;
			ref.document.title = title;
		} else {
			window.setTimeout(setContent(ref, content, title), 2);
		}
	}
}

function maximizeWindow(top) {
	if (parseInt(navigator.appVersion) > 3) {
		if (navigator.appName=="Netscape") {
			if (top.screenX>0 || top.screenY>0) {
				top.moveTo(0,0);
			}
			if (top.outerWidth < screen.availWidth) {
				top.outerWidth=screen.availWidth;
			}
			if (top.outerHeight < screen.availHeight) {
				top.outerHeight=screen.availHeight;
			}
		} else {
			top.moveTo(-4,-4);
			top.resizeTo(screen.availWidth + 8, screen.availHeight + 8);
		}
	}
}

function errorHandler(desc, page, line, chr)  {
	alert(
		'Um erro de JavaScript ocorreu! \n' +
		'Caso nao consiga continuar usando o sistema, contate seu administrador.\n' +
		'\nDescricao do erro: \t' + desc +
		'\nEndereco da pagina:\t' + page +
		'\nNumero da linha:   \t' + line +
		'\nCaractere da linha:\t' + chr
	)
	return true
}

function ajustContent(content) {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = document.width-37;
			winH = document.height-197;
			document.getElementById(content).style.height = winH;
			document.getElementById(content).style.width = winW;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth-9;
			winH = document.body.offsetHeight-4;
			document.getElementById(content).style.height = '100%';
			document.getElementById(content).style.width = winW;
		}
	}
}

function searchPopup(url) {
	win_width = 0;
	win_height = 0;
	if (screen.availWidth >= 1024) {
		win_width = 800;
		win_height = 600;
	} else {
		win_width = 640;
		win_height = 480;
	}

	return searchPopupWH(url, win_width, win_height);
}

function searchPopupWH(url, win_width, win_height) {
	win_top = Math.round((screen.availHeight - win_height) / 2);
	win_left = Math.round((screen.availWidth - win_width) / 2);

	return window.open(url, null,
		'left=' + win_left + ', top=' + win_top + ', width=' + win_width + ', height=' + win_height + 
		', scrollbars=yes, status=yes, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}

function submitFormMethod(form, method){
	document.getElementById(form).method.value = method; 
	document.getElementById(form).submit();
}

function setFormProperty(form, property, value){
	eval("document.getElementById('" + form + "')." + property + ".value = '" + value + "';");
}

function center( element ) {
	var frame = document.getElementById(element + "_frame");
	var el = document.getElementById(element);
	
	el.style.left = Math.round((screen.availWidth - 500) / 2);
	
	frame.style.left = Math.round((screen.availWidth - 500) / 2);
	frame.style.height = el.style.height;
}